
/**
 * 使用 access 判断文件权限
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char **argv)
{
    if (argc < 2)
    {
        printf("Usage : %s <files...>\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    int i = 1;
    for (; i < argc; ++i)
    {
        if (access(argv[i], F_OK) != 0)
        {
            printf("%s not found!\n", argv[i]);
        }

        if (access(argv[i], R_OK) == 0)
        {
            printf("%s cat read!\n", argv[i]);
        }

        if (access(argv[i], W_OK) == 0)
        {
            printf("%s cat write!\n", argv[i]);
        }

        if (access(argv[i], X_OK) == 0)
        {
            printf("%s cat execute!\n", argv[i]);
        }
    }
    return 0;
}